const mongoose = require('mongoose');
// 加密
const bcrypt = require('bcrypt');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
  username: { type: String, required: true },
  password: { type: String, required: true, set(val) {
    // 密码加密，等级10
    return bcrypt.hashSync(val, 10)
  } },
  area: { type: Array, required: true  },
  age: { type: Number, required: true },
  date: { type: Date, default: Date.now }
})

const User = mongoose.model('user', UserSchema)

module.exports = User;